﻿using ASP;
using HKB.Common;
using HKB.Web;
using HKB.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;

public partial class Member_Shop_ProductSale : Member, IRequiresSessionState
{
	protected DefaultProfile profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax applicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.labPage.Text = "1";
			this.GridViewDataBound();
		}
	}
 
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string text = Text.CheckNumList(Fetch.GetOrPost("Product_Select"));
		Shop_Product shop_Product = new Shop_Product(this.conn);
		if (text != "")
		{
			string text2 = text;
			string[] array = text2.Split(new char[]
			{
				','
			});
			for (int i = 0; i < array.Length; i++)
			{
				if (e.CommandName.ToString() == "StopSale")
				{
					int num = this.conn.Execute("delete HL_GroupShopProduct where MainProductID =" + int.Parse(array[i]));
				}
			}
			int num2 = shop_Product.EditSaleProductProtity(text2, e.CommandName.ToString());
			this.GridViewDataBound();
		}
	}

	protected void QucikSearch_Click(object sender, EventArgs e)
	{
		this.GridViewDataBound();
	}

	protected void GridViewDataBound()
	{
		string str = base.user.UserID.ToString();
		string text = " Select ProductID,ProductName,ProductImageUrl,ProductSmallImageUrl,Stocks,Hits,BidTimes,NeedPresentExp, case when ProductType =1 then StandPrice ";
		text += " when (ProductType=3 and TeamNum=1)  then TeamPrice1 when(ProductType=3 and TeamNum=2) then TeamPrice2 when(ProductType=3 and TeamNum=3) then TeamPrice3 when(ProductType=3 and TeamNum=4) then TeamPrice4 when(ProductType=3 and TeamNum=5) then TeamPrice5 when ProductType =4 then StandPrice when ProductType =5 then StandPrice else AuctionStartPrice end as StandPrice, DATEDIFF(s,BeginDate,EndDate) as LeftTime,ProductType, CurrentPrice,BeginDate,ClassID ";
		text = text + " From HLShop_Product WHERE EnableSale=1 and Stocks>=0 and DateDiff(s,EndDate,getdate())<=0 and SalerID=" + str + " ";
		string text2 = Text.ReplaceBadChar(this.searchProductType.SelectedValue);
		string text3 = Text.ReplaceBadChar(this.ProductName.Text);
		string text4 = Text.ReplaceBadChar(this.ProductType.SelectedValue);
		//bool @checked = this.bid.Checked;
		//bool checked2 = this.discount_join.Checked;
		string text5 = Text.ReplaceBadChar(this.show_type.SelectedValue);
		//if (@checked)
		//{
		//    text += " and (BidTimes>0 Or BuyTimes>0)";
		//}
		//if (checked2)
		//{
		//    text += " and (Discount<100 and Discount>0)";
		//}
		if (text2 != "-1")
		{
			text = text + " and IsElite=" + text2;
		}
		if (text3 != "")
		{
			text = text + " and ProductName like '%" + text3 + "%'";
		}
		if (text4 != "-1")
		{
			text = text + " and ProductType='" + text4 + "'";
		}
		if (text5 != "-1")
		{
			string text6 = text5;
			switch (text6)
			{
				case "1":
					text += " Order By BeginDate Desc";
					break;
				case "2":
					text += " Order By BeginDate Asc";
					break;
				case "3":
					text += " Order By StandPrice Desc";
					break;
				case "4":
					text += " Order By StandPrice Asc";
					break;
				case "5":
					text += " Order By Hits Desc";
					break;
				case "6":
					text += " Order By Hits Asc";
					break;
				case "7":
					text += " Order By Stocks Desc";
					break;
				case "8":
					text += " Order By Stocks Asc";
					break;
			}
		}
		else
		{
			text += " order By ProductID Desc";
		}

		//获取数据源
		PagedDataSource pds = new PagedDataSource();
		DataTable dataTable = this.conn.GetDataTable(text);
		pds.DataSource = dataTable.DefaultView;
		//设置允许分页
		pds.AllowPaging = true;
		//设置在单页上显示的条数
		pds.PageSize = 5;
		//获取或设置当前页的索引
		pds.CurrentPageIndex = Int32.Parse(labPage.Text) - 1;

		//设置页的总数
		LabCountPage.Text = pds.PageCount.ToString();
		//设置按钮的可操作性
		lbtnDownPage.Enabled = true;
		lbtnFirstPage.Enabled = true;
		lbtnNextPage.Enabled = true;
		lbtnpritPage.Enabled = true;
		if (pds.CurrentPageIndex < 1)
		{
			lbtnFirstPage.Enabled = false;
			lbtnpritPage.Enabled = false;
		}
		if (pds.CurrentPageIndex == pds.PageCount - 1)
		{
			lbtnDownPage.Enabled = false;
			lbtnNextPage.Enabled = false;
		}
		this.Repeater1.DataSourceID = "";
		this.Repeater1.DataSource = pds;
		this.Repeater1.DataBind();
	}
	protected void btn_editProducts_Click(object sender, EventArgs e)
	{
		string text = Text.CheckNumList(Fetch.GetOrPost("Product_Select"));
		if (text == "")
		{
			this.WriteErrMsg("", "未选中编辑项", "");
		}
		else
		{
			base.Response.Redirect("EditProducts.aspx?tag=Sale&productIDS=" + text);
		}
	}

	//设置首页按钮功能
	protected void lbtnFirstPage_Click(object sender, EventArgs e)
	{
		labPage.Text = "1";
		this.GridViewDataBound();
	}
	//设置上一页按钮功能
	protected void lbtnpritPage_Click(object sender, EventArgs e)
	{
		labPage.Text = (Int32.Parse(labPage.Text) - 1).ToString();
		this.GridViewDataBound();
	}
	//设置下一页按钮功能
	protected void lbtnNextPage_Click(object sender, EventArgs e)
	{
		labPage.Text = (Int32.Parse(labPage.Text) + 1).ToString();
		this.GridViewDataBound();
	}
	//设置尾页按钮功能
	protected void lbtnDownPage_Click(object sender, EventArgs e)
	{
		labPage.Text = LabCountPage.Text;
		this.GridViewDataBound();
	}

	protected void Repeater1_ItemDataBound(object source, RepeaterCommandEventArgs e)
	{
		string text = e.CommandArgument.ToString();
		Shop_Product shop_Product = new Shop_Product(this.conn);
		if (text != "")
		{
			string text2 = text;
			string[] array = text2.Split(new char[]
			{
				','
			});
			for (int i = 0; i < array.Length; i++)
			{
				if (e.CommandName.ToString() == "StopSale")
				{
					int num = this.conn.Execute("delete HL_GroupShopProduct where MainProductID =" + int.Parse(array[i]));
				}
			}
			int num2 = shop_Product.EditSaleProductProtity(text2, e.CommandName.ToString());
			this.GridViewDataBound();
		}
	}
}
